<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta name="author" content="lushu">
		<title>卡帐户充值</title>
		<script language="javascript" type="text/javascript" src="../script/print.js"></script>
		<script language="javascript" src="../script/common.js" type="text/javascript"></script>
		<script language="javascript" src="../script/card.js" type="text/javascript"></script>
		<script language="javascript" type="text/javascript">
			//初始化页面信息
			var Page;
			var data;
			function initPageElements(){
				Common.initDict(Page.operationForm.accCode,TX.AccountType.deposit());
				Common.initDict(Page.operationForm.payType,Common.getSubsetItems("pay_type",TX.PAYMENT_TYPE));
				Page.options.disLoyalty = false;		//不显示积分余额
				changePayment(Page.operationForm.payType);
				Page.checkAuthority = function(result){
					if (result.cardUser.type !=CardUserType.NAME){
						showWarning("只有个人卡可以充值");
						return false;
					}
					if (Page.raw.card.grayFund || Page.raw.card.grayPoint){
						//showWarning("卡片被灰锁，虽然可以继续进行充值，但是建议尽快进行解灰操作。");
						showWarning("卡片被灰锁，请先进行解灰操作。");
						return false;						
					}
					return true;
				}
				Page.bill = "trade_in_bill";
				Page.cleanUp = function(){
					changePayment(Page.operationForm.payType);
				}
				Page.preResult = function(){
					showInformation("充值成功");
				}
				Page.postResult = function(){
					if(Page.raw.user.cardUser.invoiceType == InvoiceType.DEPOSIT)
						TX.Invoice.saveInvoice(Page.raw.user.cardUser.uniqueId
											 , Page.raw.user.card.asn
											 , Page.amountInSystem(data.amount)
											 );
				}
			}
			
			function changePayment(obj){
				var payType;
				if (obj)
					payType = obj.value;
				var extraInput = "";
				if(payType==Constants.PAYMENT_BANK){
					extraInput =  $("bankPaymentDiv").innerHTML;
				}
				$("payTypeArea").innerHTML = extraInput;
			}
			
			//充值
			function deposit(){
				if (!Page.raw || !Page.raw.card){
					showWarning("请先读卡");
					return;
				}
				if(!checkForm(Page.operationForm.id))
					return;
				data = Common.getValues(Page.operationForm);
				var confirmString =   "充值卡号:" + Page.raw.card.asn + TX.SHOW_INFO_LINEBREAK
									+ "帐户类型:" + Common.getText('account_type',data.accCode) + TX.SHOW_INFO_LINEBREAK
									+ "帐户单位:" + data.unit + TX.SHOW_INFO_LINEBREAK
									+ "充 值 额:" + data.amount + TX.SHOW_INFO_LINEBREAK
									+ "支付类型:" + Common.getText("pay_type",data.payType);
				if(data.bankCard){
					confirmString += TX.SHOW_INFO_LINEBREAK+"银行卡卡号:"+data.bankCard
									+TX.SHOW_INFO_LINEBREAK+"银行卡交易流水号:"+data.bankTrace;
					data.bankTrade = {};
					data.bankTrade.acquirerUniqueId = data.acquirerUniqueId;
					data.bankTrade.bankCard = data.bankCard;
					data.bankTrade.bankTrace = data.bankTrace;
				}
				if(showQuestion(confirmString)){
					Page.operation.disabled = true;
					try{
						var res = cardDeposit(Page.raw.card.asn,
											Page.amountInSystem(data.amount),
											data.accCode,
											data.payType,
											data.bankTrade,
											Page.raw.card.pin);
						if(res == null) 
							return;
// 						DWR.call('txQueryService.getTrade',res.id,TX.Trade.showResult);
 						TX.Trade.showResult(res)
					}catch(e){
						Page.operation.disabled = (e.type=='card');
						showError(e.description);
					}
				}
			}
		</script>
	</head>
	<body onload="TX.Trade.init()">
		<div class="nav"><div id="nav">&nbsp;</div></div>
		<div id="operationFormDiv">
			<form id="operationForm" name="operationForm">
				<div class="form">
					<div class="formTitle">
						卡片信息
					</div>
					<span id="readonlyInfo"></span>
				</div>
					
				<div class="form">
					<div class="formTitle">充值信息</div>
					<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label8">
						<tr>
							<td><label>帐户类型</label> <select name="accCode" onchange="TX.Trade.changeAccCode(this);"></select><span class="des">*</span></td>
							<td><label>充 值 额</label> <input name="amount" type="text" onblur="Page.amountValidator(this)"><span class="des">*</span></td>
						</tr>
						<tr>
							<td><label>支付类型</label> <select name="payType" onchange="changePayment(this)"><option></option></select><span class="des">*</span></td>
							<td></td>
						</tr>
					</table>
					<div id="payTypeArea"></div>
				</div>
				<p>
					<button onclick="TX.Trade.ReadCard()">读 卡</button>
					<button name="operation" onclick="deposit();">充 值</button>
					<button onclick="TX.Trade.reset()">重 置</button>
				</p>
			</form>
			<div style="display:none;" id="bankPaymentDiv">
				<table cellSpacing="0" cellPadding="4" width="100%" border="0" class="col2 label8">
					<tr>
						<!--
						<td><label>银行卡所属机构</label> <input type='text' name='acquirerUniqueId' readonly value='9001' onblur="checkV(this,'long',true)"> <span class="des">*</span></td>
						-->
						<td><label>银行卡卡号</label> <input type='text' name='bankCard' value='' onblur="checkV(this,'bankCard',true)"> <span class="des">*</span></td>
						<td><label>银行卡交易流水号</label> <input type='text' name='bankTrace' value='' onblur="checkV(this,'long',true)"> <span class="des">*</span></td>
					</tr>
				</table>
			</div>
		</div>
		
		<div id="printSheetDiv" style="display:none;">
			<div class="form">
				<div class="formTitle">充值明细</div>
				<div id="mainTrade"></div>
			</div>
			<p>
				<button onclick="TX.Trade.goFirstPage()">返 回</button>
			</p> 
		</div>
		
		<div id="billDiv" class="form" width="100% " style="display:none;">
			<div class="formTitle">
				<div class="l">交易凭证</div>
				<div class="r">
					<button onclick="WebPrint.preview('content')">打印预览</button>
			 		<button onclick="WebPrint.print('content')">打印</button>
			 		<button onclick="TX.Trade.goFirstPage()">返 回</button>
				</div>
			</div>
			<div id="content" align='center'></div>
		</div>
	</body>
</html>